<?php
    foreach($categories as $row){
        $categories_aux[] = $row;
    }
?>
<h1>Registrar nuevo producto (Paso 2 de 3)</h1>
<input type="hidden" name="hdProductId" value="<?php echo $product->getId(); ?>" />
<table width="100%" class="table_list" border="1" cellspacing="0" cellpadding="5">
    <thead>
        <tr>
            <td colspan="2" align="center">Datos Generales</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Nombre</td>
            <td><?php echo $product->getName(); ?></td>
        </tr>
        <tr>
            <td>Url</td>
            <td>http://www.misitio.com/product/<?php echo $product->getUrl(); ?></td>
        </tr>
        <tr>
            <td>Descripción</td>
            <td>
                <?php echo $product->getDescription(); ?>
            </td>
        </tr>
        <tr>
            <td>Categoría</td>
            <td>
                <ul>
                    <?php foreach($categories_aux as $category1){ ?>
                        <?php if($category1->getParentId()==null){ ?>
                            <li>
                                <?php if($product->getCategoryId()==$category1->getId()){ ?>
                                    <input type="radio" checked="checked" disabled="disabled" />
                                <?php } ?>
                                <?php echo $category1->getName(); ?>
                            </li>
                            <ul>
                                <?php foreach($categories_aux as $category2){ ?>
                                    <?php if($category2->getParentId()==$category1->getId()){ ?>
                                        <li>
                                            <?php if($product->getCategoryId()==$category2->getId()){ ?>
                                                <input type="radio" checked="checked" disabled="disabled" />
                                            <?php } ?>
                                            <?php echo $category2->getName(); ?>
                                        </li>
                                        <ul>
                                            <?php foreach($categories_aux as $category3){ ?>
                                                <?php if($category2->getId()==$category3->getParentId()){ ?>
                                                <li>
                                                    <?php if($product->getCategoryId()==$category3->getId()){ ?>
                                                        <input type="radio" checked="checked" disabled="disabled" />
                                                    <?php } ?>
                                                    <?php echo $category3->getName(); ?>
                                                </li>
                                                <?php } ?>
                                            <?php } ?>
                                        </ul>
                                    <?php } ?>
                                <?php } ?>
                            </ul>
                        <?php } ?>
                    <?php } ?>
                </ul>
            </td>
        </tr>
        <tr>
            <td>Precio Estándar</td>
            <td>S/.<?php echo $product->getPrice(); ?></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><b>Atributos</b></td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <table width="100%">
                    <tr>
                        <td>
                            Atributo Personalizado
                            <select id="sCustomAttribute">
                                <option value="">-Seleccione-</option>
                                <?php foreach($custom_attributes as $custom_attribute){ ?>
                                <option value="<?php echo $custom_attribute->getId(); ?>"><?php echo $custom_attribute->getName(); ?></option>
                                <?php } ?>
                            </select>
                        </td>
                        <td>
                            Valor de Atributo Personalizado
                            <select id="sCustomAttributeOption">
                                <option value="">-Seleccione Atributo Personalizado-</option>
                            </select>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
$(document).ready(function(){
    $("#sCustomAttribute").change(function(){
        var custom_attribute_id = $(this).val();
        $.ajax({
            type: "post",
            url: "<?php echo url_for("@load_custom_attribute_option"); ?>",
            dataType: "json",
            data: {
                custom_attribute_id: custom_attribute_id
            },
            success: function(json){
                $("#sCustomAttributeOption").find('option').remove().end();
                if(json.custom_attribute_options.length>0){
                    for(var i=0; i<json.custom_attribute_options.length; i++){
                        $("#sCustomAttributeOption").append("<option value=" + json.custom_attribute_options[i].id + ">" + json.custom_attribute_options[i].value + "</option>");
                    }
                }else{
                    $("#sCustomAttributeOption").append("<option value=\"\">-Seleccione Atributo Personalizado-</option>");
                }
            }
        });
    });
});
</script>